package org.infodavid.common.persistence;

import org.infodavid.common.model.IApplicationSettings;
import org.infodavid.common.model.ICategory;
import org.infodavid.common.model.IDocument;
import org.infodavid.common.model.IDocumentCategory;
import org.infodavid.common.model.IDocumentVersion;
import org.infodavid.common.model.IOrganization;
import org.infodavid.common.model.IPerson;
import org.infodavid.common.model.IUser;
import org.infodavid.common.model.IUserGroup;

/**
 * The Class DataServiceProvider.
 */
public class DataServiceProvider {

  /** The singleton. */
  private static final DataServiceProvider SINGLETON = new DataServiceProvider();

  /**
   * Gets the instance.
   * @return the factory.
   */
  public static DataServiceProvider getInstance() {
    return SINGLETON;
  }

  /**
   * The constructor.
   */
  protected DataServiceProvider() {
    super();
  }

  /**
   * Gets the data service.
   * @param data the data object
   * @return the data service
   */
  @SuppressWarnings("rawtypes")
  public IDataService getDataService(final IDataObject<?> data) {
    IDataService result;

    if (data instanceof IUser || data instanceof IUser) {
      result = UserDataService.getInstance();
    }
    else if (data instanceof IUserGroup || data instanceof IUserGroup) {
      result = UserGroupDataService.getInstance();
    }
    else if (data instanceof IOrganization || data instanceof IOrganization) {
      result = OrganizationDataService.getInstance();
    }
    else if (data instanceof IPerson || data instanceof IPerson) {
      result = PersonDataService.getInstance();
    }
    else if (data instanceof IDocumentVersion || data instanceof IDocumentVersion) {
      result = DocumentVersionDataService.getInstance();
    }
    else if (data instanceof IDocument || data instanceof IDocument) {
      result = DocumentDataService.getInstance();
    }
    else if (data instanceof ICategory || data instanceof IDocumentCategory) {
      result = DocumentCategoryDataService.getInstance();
    }
    else if (data instanceof IApplicationSettings) {
      result = ApplicationSettingsDataService.getInstance();
    }
    else {
      result = null;
    }

    return result;
  }
}
